<template>
  <div class="content-box">
    <nav-title title="入公司前工作经历" />
    <div class="line">
      <span class="important">*</span>
      <div class="label">开始时间</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="expwork.startDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">结束时间</div>
      <div class="value">
        <group>
          <datetime :min-year="1900" :max-year="2100" value-text-align="left" placeholder="请选择" v-model="expwork.endDt"></datetime>
        </group>
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">工作单位</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="expwork.cCompany">
      </div>
    </div>
    <div class="line">
      <span class="important">*</span>
      <div class="label">职务</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="expwork.cPosition">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">证明人及职务</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="expwork.cDescrlong">
      </div>
    </div>
    <div class="line">
      <span class="important"></span>
      <div class="label">联系电话</div>
      <div class="value">
        <input type="text" placeholder="请在此输入" v-model="expwork.cPhone">
      </div>
    </div>
    <div class="submit-btn" @click="save">
      保存
    </div>
    <div class="remove-btn" @click="remove">
      删除
    </div>
  </div>

</template>

<script>
import { Datetime, Group } from 'vux'
import { saveWork,delWork } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    Datetime, Group
  },
  data() {
    return {
      expwork:{
        rsHireId: '',
        startDt:''
      },
      expwkDel:{
        rsHireId: '',
        cSeqno: ''
      }
    }
  },
  created() {
    this.getexps()
    if(this.$store.state.hid){
      this.expwork.rsHireId = this.$store.state.hid
      this.expwkDel.rsHireId = this.$store.state.hid
    }
  },
  methods: {
    save() {
      const that = this
      if(that.expwork.startDt === ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择开始时间'
        });
        return;
      }
      if(that.expwork.endDt === ''){
        this.$vux.alert.show({
          title: '警告',
          content: '请选择结束时间'
        });
        return;
      }

      if(!that.expwork.cCompany){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入工作单位'
        });
        return;
      }
      if(that.expwork.cPosition == ' ' || that.expwork.cPosition == undefined){
        this.$vux.alert.show({
          title: '警告',
          content: '请输入职务'
        });
        return;
      }

      console.log(that.expwork)
      saveWork(json2Form(that.expwork)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {

      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delWork(json2Form(_this.expwkDel)).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                //删除成功
                _this.$vux.alert.show({
                  title: '提示',
                  content: '删除成功',
                  onHide () {
                    _this.$router.push('/informationCollection/userInfo');
                  }
                })
              }else{
                _this.$vux.alert.show({
                  title: '',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({
                  
                })
            })

          }
        })

    },
    getexps() {
      if(this.$route.params.workexp){
        this.expwork.startDt = this.$route.params.workexp.startDt
        this.expwork.endDt = this.$route.params.workexp.endDt
        this.expwork.cCompany = this.$route.params.workexp.cCompany
        this.expwork.cPosition = this.$route.params.workexp.cPosition
        this.expwork.cDescrlong = this.$route.params.workexp.cDescrlong
        this.expwork.cPhone = this.$route.params.workexp.cPhone
        this.expwkDel.cSeqno = this.$route.params.workexp.cSeqno
        this.expwork.cSeqno = this.$route.params.workexp.cSeqno
      }
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
.vux-cell-value,.vux-cell-placeholder{ color: #000;font-size:13px; }
</style>
